package com.ruoyi.ucar.util;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.utils.DateUtils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class NanoTimestampUtil {
    // 线程安全的日期格式化器
    private static final DateTimeFormatter FORMATTER =
            DateTimeFormatter.ofPattern("yyyyMMddHHmmss");

    public static String getNanoTimestamp() {
        Instant instant = Instant.now();
        LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

        // 获取秒级时间部分
        String baseTime = FORMATTER.format(ldt);

        // 获取纳秒部分并补齐9位
        String nanos = String.format("%09d", instant.getNano());

        return baseTime + nanos;
    }

    public static void main(String[] args) {
        System.out.println( DateUtil.offsetHour(DateUtil.parse(DateUtils.getTime()) ,30)); // 示例输出：20250617153045123456789
    }
}
